package com.smedi.ismedi.inmail.core.domain.service.impl;

import com.smedi.ismedi.authority.starter.util.AuthorityUtil;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.LoginLog;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.Person;
import com.smedi.ismedi.inmail.core.domain.repository.LoginLogRepository;
import com.smedi.ismedi.inmail.core.domain.service.LoginLogDomainService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.time.LocalDateTime;

/**
 * 业务服务实现类
 *
 * @author jiangqinxuan   niuyanling
 * @date 2021/07/27
 */
@Slf4j
@Service
@AllArgsConstructor
public class LoginLogDomainServiceImpl implements LoginLogDomainService {
    private final LoginLogRepository loginLogRepository;

    private final AuthorityUtil authorityUtil;

    @Override
    public Long create(LoginLog loginLog) {
        loginLog.setLoginTime(LocalDateTime.now());
        loginLog.setLoginUser(new Person(authorityUtil.getPersonId()));
        loginLog.setLogoutTime(LocalDateTime.now().plusMinutes(1L));
        return loginLogRepository.create(loginLog);
    }

    @Override
    public void update(LoginLog loginLog) {
        loginLogRepository.update(loginLog);
    }
}
